package com.zhouyou.http.model.body;

import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.body.UIProgressResponseCallBack;
import com.zhouyou.http.callback.CallBack;
import com.zhouyou.http.callback.ProgressDialogCallBack;
import com.zhouyou.http.demo.slice.UploadAbilitySlice;
import com.zhouyou.http.demo.view.HorizontalProgressDialog;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.utils.FileUtils;
import com.zhouyou.http.model.utils.ToastUtils;
import com.zhouyou.http.utils.HttpLog;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.aafwk.ability.delegation.IAbilityDelegator;
import org.junit.Test;

import java.io.File;

import static com.zhouyou.http.demo.constant.AppConstant.UPLOAD_FILE;
import static org.junit.Assert.*;

public class UIProgressResponseCallBackTest {
    private static IAbilityDelegator sAbilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();

    @Test
    public void onResponseProgress() {
        final UIProgressResponseCallBack listener = new UIProgressResponseCallBack() {
            @Override
            public void onUIResponseProgress(long bytesRead, long contentLength, boolean done) {
                int progress = (int) (bytesRead * 100 / contentLength);
                assertTrue("contentLength  is not -1? ==", contentLength > -1);
            }
        };
        File file = FileUtils.getDistributedDir(sAbilityDelegator.getAppContext(), "1.jpg");
        EasyHttp.post(UPLOAD_FILE)
                //如果有文件名字可以不用再传Type,会自动解析到是image/*
                .params("avatar", file, file.getName(), listener)
                //.params("avatar", file, file.getName(),MediaType.parse("image/*"), listener)
                .accessToken(true)
                .timeStamp(true)
                .execute(new CallBack<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onSuccess(String s) {

                    }
                });
    }
}